package com.tourism.controller;

import com.github.pagehelper.PageInfo;
import com.tourism.entity.OrderInfo;
import com.tourism.entity.OrderPayInfo;
import com.tourism.entity.OrderQuery;
import com.tourism.exception.GlobalException;
import com.tourism.service.OrderInfoService;
import com.tourism.util.common.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 订单相关的控制器
 * @Author z
 * @Date 2021-03-01 20:40
 */
@Controller
@RequestMapping("/order")
public class OrderController {


    @Autowired
    private OrderInfoService orderInfoService;

    /**
     * 根据订单id查询订单信息
     *
     * @param id
     * @return
     */
    @GetMapping("/getOrderInfoById")
    @ResponseBody
    public OrderInfo getLineById(Long id) {
        return orderInfoService.getOrderInfoById(id);
    }

    /**
     * 根据ID删除线路订单
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteOrderInfoById")
    @ResponseBody
    public Response deleteOrderInfoById(Long id) {
        return Response.success(orderInfoService.deleteOrderInfoById(id));

    }
    /**
     * 新增订单
     *
     * @param orderInfo
     * @return
     */
    @PostMapping("/addOrderInfo")
    @ResponseBody
    public Response addLine(@RequestBody OrderInfo orderInfo) throws GlobalException {
        return Response.success(orderInfoService.addOrderInfo(orderInfo));

    }


    /**
     * 查询订单列表
     *
     * @param orderQuery
     * @return
     */
    @PostMapping("/getOrderInfoList")
    @ResponseBody
    public PageInfo<OrderInfo> getOrderInfoList(@RequestBody OrderQuery orderQuery) {
        return orderInfoService.getOrderInfoList(orderQuery);
    }

    /**
     * 支付线路订单
     *
     * @param orderPayInfo
     * @return
     */
    @PostMapping("/updateOrderPayInfo")
    @ResponseBody
    public Response updateOrderPayInfo(@RequestBody OrderPayInfo orderPayInfo) {

        return Response.success(orderInfoService.updateOrderPayInfo(orderPayInfo));

    }

}
